import {Component, EventEmitter, OnInit, Output} from '@angular/core';
// 定义主题参数
type AlertTheme = 'primary' | 'danger' | 'warning' | 'secondary' | 'success' | 'info' | 'dark' | 'light';

// 限定参数
export interface AlertOption {
  content: string;
  theme?: AlertTheme;
}

@Component({
  selector: 'app-alert',
  standalone: true,
  imports: [],
  templateUrl: './alert.component.html',
  styleUrls:[]
})
export class AlertComponent implements OnInit{

  // Required将对象类型AlertOption的所有可选属性转化为必填属性
  options: Required<AlertOption> = {
    content: '',
    theme: 'primary',
  }
  // 注册关闭的输出事件
  @Output() readonly closed = new EventEmitter();

  constructor() { }

  ngOnInit(): void {
    this.options.theme ='info';
    this.options.content = 'info';
  }

  // 获取class
  get wrapClass(): string {
    return `alert alert-${this.options.theme}`
  }

  // 合并默认参数与传入的参数
  setOptions(options: AlertOption): void {
    this.options = {...this.options, ...options}
  }
}
